package com.clock.shiro.config;

import com.clock.shiro.JwtFilter;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Configuration
public class ShiroFilterConfig {

   /* @Bean("shiroFilter")
    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager);

        Map<String, String> filterMap = new LinkedHashMap<>();
        filterMap.put("/account/login", "anon");
        filterMap.put("/account/register", "anon");
        filterMap.put("/account/checkUserInf", "anon");

        //jwt过滤 处了上面两个 所有请求都需要过一个shiro的认证
        filterMap.put("/**", "jwt");
        Map<String, Filter> filters = new HashMap<>();
        filters.put("jwt", new JwtFilter());

        //其他特殊权限的路径
        //样例 ： filterMap.put("路径","权限");
        filterMap.put("/managerUser/**","roles[顶级管理]");

        shiroFilter.setFilters(filters);
        shiroFilter.setFilterChainDefinitionMap(filterMap);

        return shiroFilter;
    }*/

}
